//
//  UIBarButtonItem+Extension.swift
//  sina
//
//  Created by 江先铨 on 15/11/19.
//  Copyright © 2015年 jxqstatic. All rights reserved.
//

import UIKit

extension UIBarButtonItem {

    convenience init(imageName: String, target: AnyObject?, actionName: String?) {
    
       let btn = UIButton(type: .Custom)
       btn.setImage(UIImage(named: imageName), forState:.Normal)
       btn.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
       
        //判断只有当两个人都有值 的时候在执行下面的方法
        if let action = actionName, targetObj = target {
        
          btn.addTarget(targetObj, action: Selector(action), forControlEvents: .TouchUpInside)
        }
        
        
       btn.sizeToFit()
        
       self.init(customView : btn)
    }

}
